{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## K-Means Clustering - Customer Segmentation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Overview**<br>\n",
    "Data is downloaded from - https://archive.ics.uci.edu/ml/datasets/online+retail\n",
    "\n",
    "The steps are broadly:\n",
    "1. Read and understand the data\n",
    "2. Clean the data\n",
    "3. Prepare the data for modelling\n",
    "4. Modelling\n",
    "5. Final analysis and recommendations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. Read and visualise the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "import datetime as dt\n",
    "\n",
    "import sklearn\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn.metrics import silhouette_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InvoiceNo</th>\n",
       "      <th>StockCode</th>\n",
       "      <th>Description</th>\n",
       "      <th>Quantity</th>\n",
       "      <th>InvoiceDate</th>\n",
       "      <th>UnitPrice</th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>Country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>536365</td>\n",
       "      <td>85123A</td>\n",
       "      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>2.55</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>536365</td>\n",
       "      <td>71053</td>\n",
       "      <td>WHITE METAL LANTERN</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>536365</td>\n",
       "      <td>84406B</td>\n",
       "      <td>CREAM CUPID HEARTS COAT HANGER</td>\n",
       "      <td>8</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>2.75</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029G</td>\n",
       "      <td>KNITTED UNION FLAG HOT WATER BOTTLE</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029E</td>\n",
       "      <td>RED WOOLLY HOTTIE WHITE HEART.</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  InvoiceNo StockCode                          Description  Quantity  \\\n",
       "0    536365    85123A   WHITE HANGING HEART T-LIGHT HOLDER         6   \n",
       "1    536365     71053                  WHITE METAL LANTERN         6   \n",
       "2    536365    84406B       CREAM CUPID HEARTS COAT HANGER         8   \n",
       "3    536365    84029G  KNITTED UNION FLAG HOT WATER BOTTLE         6   \n",
       "4    536365    84029E       RED WOOLLY HOTTIE WHITE HEART.         6   \n",
       "\n",
       "          InvoiceDate  UnitPrice  CustomerID         Country  \n",
       "0 2010-12-01 08:26:00       2.55     17850.0  United Kingdom  \n",
       "1 2010-12-01 08:26:00       3.39     17850.0  United Kingdom  \n",
       "2 2010-12-01 08:26:00       2.75     17850.0  United Kingdom  \n",
       "3 2010-12-01 08:26:00       3.39     17850.0  United Kingdom  \n",
       "4 2010-12-01 08:26:00       3.39     17850.0  United Kingdom  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# read the dataset\n",
    "retail_df = pd.read_excel(\"data/retail.xlsx\")\n",
    "retail_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 541909 entries, 0 to 541908\n",
      "Data columns (total 8 columns):\n",
      " #   Column       Non-Null Count   Dtype         \n",
      "---  ------       --------------   -----         \n",
      " 0   InvoiceNo    541909 non-null  object        \n",
      " 1   StockCode    541909 non-null  object        \n",
      " 2   Description  540455 non-null  object        \n",
      " 3   Quantity     541909 non-null  int64         \n",
      " 4   InvoiceDate  541909 non-null  datetime64[ns]\n",
      " 5   UnitPrice    541909 non-null  float64       \n",
      " 6   CustomerID   406829 non-null  float64       \n",
      " 7   Country      541909 non-null  object        \n",
      "dtypes: datetime64[ns](1), float64(2), int64(1), object(4)\n",
      "memory usage: 33.1+ MB\n"
     ]
    }
   ],
   "source": [
    "# basics of the df\n",
    "retail_df.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Clean the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "InvoiceNo       0.00\n",
       "StockCode       0.00\n",
       "Description     0.27\n",
       "Quantity        0.00\n",
       "InvoiceDate     0.00\n",
       "UnitPrice       0.00\n",
       "CustomerID     24.93\n",
       "Country         0.00\n",
       "dtype: float64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# missing values\n",
    "round(100*(retail_df.isnull().sum())/len(retail_df), 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(406829, 8)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# drop all rows having missing values\n",
    "retail_df = retail_df.dropna()\n",
    "retail_df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InvoiceNo</th>\n",
       "      <th>StockCode</th>\n",
       "      <th>Description</th>\n",
       "      <th>Quantity</th>\n",
       "      <th>InvoiceDate</th>\n",
       "      <th>UnitPrice</th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>Country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>536365</td>\n",
       "      <td>85123A</td>\n",
       "      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>2.55</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>536365</td>\n",
       "      <td>71053</td>\n",
       "      <td>WHITE METAL LANTERN</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>536365</td>\n",
       "      <td>84406B</td>\n",
       "      <td>CREAM CUPID HEARTS COAT HANGER</td>\n",
       "      <td>8</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>2.75</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029G</td>\n",
       "      <td>KNITTED UNION FLAG HOT WATER BOTTLE</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029E</td>\n",
       "      <td>RED WOOLLY HOTTIE WHITE HEART.</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  InvoiceNo StockCode                          Description  Quantity  \\\n",
       "0    536365    85123A   WHITE HANGING HEART T-LIGHT HOLDER         6   \n",
       "1    536365     71053                  WHITE METAL LANTERN         6   \n",
       "2    536365    84406B       CREAM CUPID HEARTS COAT HANGER         8   \n",
       "3    536365    84029G  KNITTED UNION FLAG HOT WATER BOTTLE         6   \n",
       "4    536365    84029E       RED WOOLLY HOTTIE WHITE HEART.         6   \n",
       "\n",
       "          InvoiceDate  UnitPrice  CustomerID         Country  \n",
       "0 2010-12-01 08:26:00       2.55     17850.0  United Kingdom  \n",
       "1 2010-12-01 08:26:00       3.39     17850.0  United Kingdom  \n",
       "2 2010-12-01 08:26:00       2.75     17850.0  United Kingdom  \n",
       "3 2010-12-01 08:26:00       3.39     17850.0  United Kingdom  \n",
       "4 2010-12-01 08:26:00       3.39     17850.0  United Kingdom  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "retail_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InvoiceNo</th>\n",
       "      <th>StockCode</th>\n",
       "      <th>Description</th>\n",
       "      <th>Quantity</th>\n",
       "      <th>InvoiceDate</th>\n",
       "      <th>UnitPrice</th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>Country</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>536365</td>\n",
       "      <td>85123A</td>\n",
       "      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>2.55</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>15.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>536365</td>\n",
       "      <td>71053</td>\n",
       "      <td>WHITE METAL LANTERN</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>20.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>536365</td>\n",
       "      <td>84406B</td>\n",
       "      <td>CREAM CUPID HEARTS COAT HANGER</td>\n",
       "      <td>8</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>2.75</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>22.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029G</td>\n",
       "      <td>KNITTED UNION FLAG HOT WATER BOTTLE</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>20.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029E</td>\n",
       "      <td>RED WOOLLY HOTTIE WHITE HEART.</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>20.34</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  InvoiceNo StockCode                          Description  Quantity  \\\n",
       "0    536365    85123A   WHITE HANGING HEART T-LIGHT HOLDER         6   \n",
       "1    536365     71053                  WHITE METAL LANTERN         6   \n",
       "2    536365    84406B       CREAM CUPID HEARTS COAT HANGER         8   \n",
       "3    536365    84029G  KNITTED UNION FLAG HOT WATER BOTTLE         6   \n",
       "4    536365    84029E       RED WOOLLY HOTTIE WHITE HEART.         6   \n",
       "\n",
       "          InvoiceDate  UnitPrice  CustomerID         Country  amount  \n",
       "0 2010-12-01 08:26:00       2.55     17850.0  United Kingdom   15.30  \n",
       "1 2010-12-01 08:26:00       3.39     17850.0  United Kingdom   20.34  \n",
       "2 2010-12-01 08:26:00       2.75     17850.0  United Kingdom   22.00  \n",
       "3 2010-12-01 08:26:00       3.39     17850.0  United Kingdom   20.34  \n",
       "4 2010-12-01 08:26:00       3.39     17850.0  United Kingdom   20.34  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# new column: amount \n",
    "retail_df['amount'] = retail_df['Quantity']*retail_df['UnitPrice']\n",
    "retail_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. Prepare the data for modelling"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- R (Recency): Number of days since last purchase\n",
    "- F (Frequency): Number of tracsactions\n",
    "- M (Monetary): Total amount of transactions (revenue contributed)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12346.0</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12347.0</td>\n",
       "      <td>4310.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12348.0</td>\n",
       "      <td>1797.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12349.0</td>\n",
       "      <td>1757.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12350.0</td>\n",
       "      <td>334.40</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CustomerID   amount\n",
       "0     12346.0     0.00\n",
       "1     12347.0  4310.00\n",
       "2     12348.0  1797.24\n",
       "3     12349.0  1757.55\n",
       "4     12350.0   334.40"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# monetary\n",
    "amount = retail_df.groupby('CustomerID')['amount'].sum()\n",
    "amount = amount.reset_index()\n",
    "amount.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>frequency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12346.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12347.0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12348.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12349.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12350.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CustomerID  frequency\n",
       "0     12346.0          2\n",
       "1     12347.0          7\n",
       "2     12348.0          4\n",
       "3     12349.0          1\n",
       "4     12350.0          1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# frequency\n",
    "# count function gets the count of each item\n",
    "frequency = retail_df.groupby('CustomerID')['InvoiceNo'].nunique()\n",
    "frequency = frequency.reset_index()\n",
    "frequency.columns = ['CustomerID', 'frequency']\n",
    "frequency.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>amount</th>\n",
       "      <th>frequency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12346.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12347.0</td>\n",
       "      <td>4310.00</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12348.0</td>\n",
       "      <td>1797.24</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12349.0</td>\n",
       "      <td>1757.55</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12350.0</td>\n",
       "      <td>334.40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CustomerID   amount  frequency\n",
       "0     12346.0     0.00          2\n",
       "1     12347.0  4310.00          7\n",
       "2     12348.0  1797.24          4\n",
       "3     12349.0  1757.55          1\n",
       "4     12350.0   334.40          1"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# merge the two dfs\n",
    "grouped_df = pd.merge(amount, frequency, on='CustomerID', how='inner')\n",
    "grouped_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# recency\n",
    "# convert to datetime\n",
    "\n",
    "# retail_df['InvoiceDate'] = pd.to_datetime(retail_df['InvoiceDate'], format='%d-%m-%Y %H:%M')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2011-12-09 12:50:00')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# compute the max date\n",
    "max_date = max(retail_df['InvoiceDate'])\n",
    "max_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InvoiceNo</th>\n",
       "      <th>StockCode</th>\n",
       "      <th>Description</th>\n",
       "      <th>Quantity</th>\n",
       "      <th>InvoiceDate</th>\n",
       "      <th>UnitPrice</th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>Country</th>\n",
       "      <th>amount</th>\n",
       "      <th>diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>536365</td>\n",
       "      <td>85123A</td>\n",
       "      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>2.55</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>15.30</td>\n",
       "      <td>373 days 04:24:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>536365</td>\n",
       "      <td>71053</td>\n",
       "      <td>WHITE METAL LANTERN</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>20.34</td>\n",
       "      <td>373 days 04:24:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>536365</td>\n",
       "      <td>84406B</td>\n",
       "      <td>CREAM CUPID HEARTS COAT HANGER</td>\n",
       "      <td>8</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>2.75</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>22.00</td>\n",
       "      <td>373 days 04:24:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029G</td>\n",
       "      <td>KNITTED UNION FLAG HOT WATER BOTTLE</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>20.34</td>\n",
       "      <td>373 days 04:24:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029E</td>\n",
       "      <td>RED WOOLLY HOTTIE WHITE HEART.</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01 08:26:00</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>20.34</td>\n",
       "      <td>373 days 04:24:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  InvoiceNo StockCode                          Description  Quantity  \\\n",
       "0    536365    85123A   WHITE HANGING HEART T-LIGHT HOLDER         6   \n",
       "1    536365     71053                  WHITE METAL LANTERN         6   \n",
       "2    536365    84406B       CREAM CUPID HEARTS COAT HANGER         8   \n",
       "3    536365    84029G  KNITTED UNION FLAG HOT WATER BOTTLE         6   \n",
       "4    536365    84029E       RED WOOLLY HOTTIE WHITE HEART.         6   \n",
       "\n",
       "          InvoiceDate  UnitPrice  CustomerID         Country  amount  \\\n",
       "0 2010-12-01 08:26:00       2.55     17850.0  United Kingdom   15.30   \n",
       "1 2010-12-01 08:26:00       3.39     17850.0  United Kingdom   20.34   \n",
       "2 2010-12-01 08:26:00       2.75     17850.0  United Kingdom   22.00   \n",
       "3 2010-12-01 08:26:00       3.39     17850.0  United Kingdom   20.34   \n",
       "4 2010-12-01 08:26:00       3.39     17850.0  United Kingdom   20.34   \n",
       "\n",
       "               diff  \n",
       "0 373 days 04:24:00  \n",
       "1 373 days 04:24:00  \n",
       "2 373 days 04:24:00  \n",
       "3 373 days 04:24:00  \n",
       "4 373 days 04:24:00  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# compute the diff\n",
    "retail_df['diff'] = max_date - retail_df['InvoiceDate']\n",
    "retail_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12346.0</td>\n",
       "      <td>325 days 02:33:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12347.0</td>\n",
       "      <td>1 days 20:58:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12348.0</td>\n",
       "      <td>74 days 23:37:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12349.0</td>\n",
       "      <td>18 days 02:59:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12350.0</td>\n",
       "      <td>309 days 20:49:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CustomerID              diff\n",
       "0     12346.0 325 days 02:33:00\n",
       "1     12347.0   1 days 20:58:00\n",
       "2     12348.0  74 days 23:37:00\n",
       "3     12349.0  18 days 02:59:00\n",
       "4     12350.0 309 days 20:49:00"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# recency\n",
    "last_purchase = retail_df.groupby('CustomerID')['diff'].min()\n",
    "last_purchase = last_purchase.reset_index()\n",
    "last_purchase.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>amount</th>\n",
       "      <th>frequency</th>\n",
       "      <th>recency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12346.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2</td>\n",
       "      <td>325 days 02:33:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12347.0</td>\n",
       "      <td>4310.00</td>\n",
       "      <td>7</td>\n",
       "      <td>1 days 20:58:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12348.0</td>\n",
       "      <td>1797.24</td>\n",
       "      <td>4</td>\n",
       "      <td>74 days 23:37:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12349.0</td>\n",
       "      <td>1757.55</td>\n",
       "      <td>1</td>\n",
       "      <td>18 days 02:59:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12350.0</td>\n",
       "      <td>334.40</td>\n",
       "      <td>1</td>\n",
       "      <td>309 days 20:49:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CustomerID   amount  frequency           recency\n",
       "0     12346.0     0.00          2 325 days 02:33:00\n",
       "1     12347.0  4310.00          7   1 days 20:58:00\n",
       "2     12348.0  1797.24          4  74 days 23:37:00\n",
       "3     12349.0  1757.55          1  18 days 02:59:00\n",
       "4     12350.0   334.40          1 309 days 20:49:00"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# merge\n",
    "grouped_df = pd.merge(grouped_df, last_purchase, on='CustomerID', how='inner')\n",
    "grouped_df.columns = ['CustomerID', 'amount', 'frequency', 'recency']\n",
    "grouped_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>amount</th>\n",
       "      <th>frequency</th>\n",
       "      <th>recency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12346.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2</td>\n",
       "      <td>325</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12347.0</td>\n",
       "      <td>4310.00</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12348.0</td>\n",
       "      <td>1797.24</td>\n",
       "      <td>4</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12349.0</td>\n",
       "      <td>1757.55</td>\n",
       "      <td>1</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12350.0</td>\n",
       "      <td>334.40</td>\n",
       "      <td>1</td>\n",
       "      <td>309</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CustomerID   amount  frequency  recency\n",
       "0     12346.0     0.00          2      325\n",
       "1     12347.0  4310.00          7        1\n",
       "2     12348.0  1797.24          4       74\n",
       "3     12349.0  1757.55          1       18\n",
       "4     12350.0   334.40          1      309"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# number of days only\n",
    "grouped_df['recency'] = grouped_df['recency'].dt.days\n",
    "grouped_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4372, 3)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# rescaling\n",
    "rfm_df = grouped_df[['amount', 'frequency', 'recency']]\n",
    "\n",
    "# instantiate\n",
    "scaler = StandardScaler()\n",
    "\n",
    "# fit_transform\n",
    "rfm_df_scaled = scaler.fit_transform(rfm_df)\n",
    "rfm_df_scaled.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>frequency</th>\n",
       "      <th>recency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.231001</td>\n",
       "      <td>-0.329362</td>\n",
       "      <td>2.322023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.293432</td>\n",
       "      <td>0.206102</td>\n",
       "      <td>-0.893733</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.012316</td>\n",
       "      <td>-0.115176</td>\n",
       "      <td>-0.169196</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.017146</td>\n",
       "      <td>-0.436455</td>\n",
       "      <td>-0.725005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.190312</td>\n",
       "      <td>-0.436455</td>\n",
       "      <td>2.163220</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     amount  frequency   recency\n",
       "0 -0.231001  -0.329362  2.322023\n",
       "1  0.293432   0.206102 -0.893733\n",
       "2 -0.012316  -0.115176 -0.169196\n",
       "3 -0.017146  -0.436455 -0.725005\n",
       "4 -0.190312  -0.436455  2.163220"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rfm_df_scaled = pd.DataFrame(rfm_df_scaled)\n",
    "rfm_df_scaled.columns = ['amount', 'frequency', 'recency']\n",
    "rfm_df_scaled.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. Modelling"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KMeans(max_iter=50, n_clusters=4)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KMeans</label><div class=\"sk-toggleable__content\"><pre>KMeans(max_iter=50, n_clusters=4)</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "KMeans(max_iter=50, n_clusters=4)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# k-means with some arbitrary k\n",
    "kmeans = KMeans(n_clusters=4, max_iter=50)\n",
    "kmeans.fit(rfm_df_scaled)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 0, 0, ..., 0, 0, 0])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kmeans.labels_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# help(KMeans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Finding the Optimal Number of Clusters\n",
    "\n",
    "### Elbow Curve Method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x201cbac39d0>]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD4CAY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MR6xN3iZHPw1y70nM8sFxgOPhl2LRJhZGjAKeAzA3asaK/AhNkM/B9hc53UxzTRcYpWZ5QFDgIUhl3LCgiGRj4EyYJ67N9dtuQ+4FTgUch2NwYFXzWyxmU0Ou5iT0BMoB54Iht0eNbPWjfXhsRj6dpS2ZrkXFovMrA3wN+AWd98Tdj0nyt1r3f0MIBcYbmbNbujNzC4Fytx9cdi1NJKR7j4UuBiYEgyNNkdJwFDgYXcfAuwDGu3YZCyGfjHQtc7rXGBrSLVIHcH499+Ap939+bDraQzBz+43gXHhVnJCRgKXBWPhM4ALzezP4ZZ04tx9a/BYBrxAZKi3OSoGiuv8enyOSCfQKGIx9D8E8s2sR3AAZCIwK+Sa4l5w8PMxYKW73xt2PSfDzDLNrH3wvCUwGlgValEnwN3vcPdcd88j8u/kdXe/KuSyToiZtQ5OECAYCrkIaJZnvLn7NmCzmfUNmr4NNNoJD0mN9UHRwt1rzOznwCtAIvC4uy8PuawTZmbPAucDHc2sGPh3d38s3KpOyEjgJ8CyYCwc4N/c/eXwSjph2cD04EyxBGCmuzfr0x1jQBbwQmTfgiTgGXefG25JJ+VG4Olgx/Uz4NrG+uCYO2VTRES+WSwO74iIyDdQ6IuIxBGFvohIHFHoi4jEEYW+iEgcUeiLiMQRhb6ISBz5/+lxhAe0kdi6AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# elbow-curve\n",
    "ssd = []\n",
    "range_n_clusters = [2, 3, 4, 5, 6, 7, 8]\n",
    "for num_clusters in range_n_clusters:\n",
    "    kmeans = KMeans(n_clusters=num_clusters, max_iter=50)\n",
    "    kmeans.fit(rfm_df_scaled)\n",
    "    \n",
    "    ssd.append(kmeans.inertia_)\n",
    "    \n",
    "# plot the SSDs for each n_clusters\n",
    "# ssd\n",
    "plt.plot(ssd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Silhouette Analysis\n",
    "\n",
    "$$\\text{silhouette score}=\\frac{p-q}{max(p,q)}$$\n",
    "\n",
    "$p$ is the mean distance to the points in the nearest cluster that the data point is not a part of\n",
    "\n",
    "$q$ is the mean intra-cluster distance to all the points in its own cluster.\n",
    "\n",
    "* The value of the silhouette score range lies between -1 to 1. \n",
    "\n",
    "* A score closer to 1 indicates that the data point is very similar to other data points in the cluster, \n",
    "\n",
    "* A score closer to -1 indicates that the data point is not similar to the data points in its cluster."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For n_clusters=2, the silhouette score is 0.8953127225457423\n",
      "For n_clusters=3, the silhouette score is 0.5880231531287353\n",
      "For n_clusters=4, the silhouette score is 0.6114134158441514\n",
      "For n_clusters=5, the silhouette score is 0.589875763645933\n",
      "For n_clusters=6, the silhouette score is 0.5838535042838963\n",
      "For n_clusters=7, the silhouette score is 0.5167945127210051\n",
      "For n_clusters=8, the silhouette score is 0.4921871237077667\n"
     ]
    }
   ],
   "source": [
    "# silhouette analysis\n",
    "range_n_clusters = [2, 3, 4, 5, 6, 7, 8]\n",
    "\n",
    "for num_clusters in range_n_clusters:\n",
    "    \n",
    "    # intialise kmeans\n",
    "    kmeans = KMeans(n_clusters=num_clusters, max_iter=50)\n",
    "    kmeans.fit(rfm_df_scaled)\n",
    "    \n",
    "    cluster_labels = kmeans.labels_\n",
    "    \n",
    "    # silhouette score\n",
    "    silhouette_avg = silhouette_score(rfm_df_scaled, cluster_labels)\n",
    "    print(\"For n_clusters={0}, the silhouette score is {1}\".format(num_clusters, silhouette_avg))\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-2 {color: black;background-color: white;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KMeans(max_iter=50, n_clusters=3)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KMeans</label><div class=\"sk-toggleable__content\"><pre>KMeans(max_iter=50, n_clusters=3)</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "KMeans(max_iter=50, n_clusters=3)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# final model with k=3\n",
    "kmeans = KMeans(n_clusters=3, max_iter=50)\n",
    "kmeans.fit(rfm_df_scaled)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 1, ..., 1, 1, 1])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kmeans.labels_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>amount</th>\n",
       "      <th>frequency</th>\n",
       "      <th>recency</th>\n",
       "      <th>cluster_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12346.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2</td>\n",
       "      <td>325</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12347.0</td>\n",
       "      <td>4310.00</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12348.0</td>\n",
       "      <td>1797.24</td>\n",
       "      <td>4</td>\n",
       "      <td>74</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12349.0</td>\n",
       "      <td>1757.55</td>\n",
       "      <td>1</td>\n",
       "      <td>18</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12350.0</td>\n",
       "      <td>334.40</td>\n",
       "      <td>1</td>\n",
       "      <td>309</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CustomerID   amount  frequency  recency  cluster_id\n",
       "0     12346.0     0.00          2      325           0\n",
       "1     12347.0  4310.00          7        1           1\n",
       "2     12348.0  1797.24          4       74           1\n",
       "3     12349.0  1757.55          1       18           1\n",
       "4     12350.0   334.40          1      309           0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# assign the label\n",
    "grouped_df['cluster_id'] = kmeans.labels_\n",
    "grouped_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='cluster_id', ylabel='amount'>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAEHCAYAAACTC1DDAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAaNklEQVR4nO3df3Bd5Z3f8fdH2BATftpyMq5laho7KT8mNbXq0GHKsCEWdgKB7EDXTBc0DVu7lGAy2SbLj5lAyTAN7RK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nHMQ2zKrmKTKzGoiIbZJuAH4l6QNK01k7ylb5W2CNpIuAh8vqfwH8paR9wO+A69P02j9JehboiojvSjoBeCxNn/0e+EvggzH2+KSk+4AtwEvAPx7EWzWrmi/Xb2ZmWXiKzMzMsvAUmVmDkPQ4cNiI8kUR8UwR/Zh5iszMzLLwFJmZmWXhgDEzsywcMGZmloUDxszMsvj/UqPtXcLGdNsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot\n",
    "sns.boxplot(x='cluster_id', y='amount', data=grouped_df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"font-family:verdana;\">\n",
    "    <h3 style=\"font-family:verdana;\">⭐Important Observations :</h3>\n",
    "    <div class=\"alert alert-block alert-info\">\n",
    "    * <i> Cluster <code>2</code> represents high monetary customers.</i><br>\n",
    "    * <i> Cluster <code>0</code> and <code>1</code> has high overlap.</i><br>\n",
    "    </div>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='cluster_id', ylabel='frequency'>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEHCAYAAABBW1qbAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAWVklEQVR4nO3df3Bd5X3n8fdXjuJQSMfBMhlqQU1iJ03IpGTiZTtlliU/bFCmLUknSck0VNOyw3SX4KTT7RQaYGm3zDJpQ7byLt0hhVZtQxzPhmw8HRRsaCjbTgqYHzUYb2wNGLixFywTinFZ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<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.boxplot(x='cluster_id', y='frequency', data=grouped_df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"font-family:verdana;\">\n",
    "    <h3 style=\"font-family:verdana;\">⭐Important Observations :</h3>\n",
    "    <div class=\"alert alert-block alert-info\">\n",
    "    * <i> Cluster <code>2</code> represents high frequency customers.</i><br>\n",
    "    * <i> Cluster <code>0</code> and <code>1</code> has high overlap.</i><br>\n",
    "    </div>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='cluster_id', ylabel='recency'>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEHCAYAAABBW1qbAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAXw0lEQVR4nO3dfZBddZ3n8feHGAFFC5AoDCEbNMEasDSWXdnZsVAGJzxYg+juOBtrh03tuotTg0SrZtyR0fJhdlJL+bj2+lCLIzU9riuT8qEMaFYCK+u6ojFhMBIQ06MRWiIkoCMYxAS++0efHDuhSW4nffvcTr9fVbfuOb9zfud+O53uT5/HX6oKSZIAjum6AEnS4DAUJEktQ0GS1DIUJEktQ0GS1Hpa1wUciVNOOaUWL17cdRmSNKts3rx5V1UtmGzZrA6FxYsXs2nTpq7LkKRZJcmPn2qZh48kSS1DQZLUMhQkSS1DQZLUMhQkSS1DQZLUMhQkSa1ZfZ/CIBgeHmZ0dHTatzs2NgbAwoULp33bS5YsYfXq1dO+XUmzn6EwoB599NGuS5A0B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flt4Nbm0NIjwB8Dj0+xxtuS/D1wO/Bj4P8expcq9cxHZ0uSWh4+kiS1PHwkdSjJt4FjD2i+rKq+10U9koePJEktDx9JklqGgiSpZShIklqGgiSp9f8B71vxigk18pIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.boxplot(x='cluster_id', y='recency', data=grouped_df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"font-family:verdana;\">\n",
    "    <h3 style=\"font-family:verdana;\">⭐Important Observations :</h3>\n",
    "    <div class=\"alert alert-block alert-info\">\n",
    "    * <i> Cluster <code>2</code> represents high recency customers.</i><br>\n",
    "    * <i> Cluster <code>0</code> represents least recent.</i><br>\n",
    "    </div>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5. Treating the Outliers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>amount</th>\n",
       "      <th>frequency</th>\n",
       "      <th>recency</th>\n",
       "      <th>cluster_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>4372.000000</td>\n",
       "      <td>4372.000000</td>\n",
       "      <td>4372.000000</td>\n",
       "      <td>4372.000000</td>\n",
       "      <td>4372.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>15299.677722</td>\n",
       "      <td>1898.459701</td>\n",
       "      <td>5.075480</td>\n",
       "      <td>91.047118</td>\n",
       "      <td>0.751372</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1722.390705</td>\n",
       "      <td>8219.345141</td>\n",
       "      <td>9.338754</td>\n",
       "      <td>100.765435</td>\n",
       "      <td>0.444273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>12346.000000</td>\n",
       "      <td>-4287.630000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>13812.750000</td>\n",
       "      <td>293.362500</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>15300.500000</td>\n",
       "      <td>648.075000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>49.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>16778.250000</td>\n",
       "      <td>1611.725000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>142.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>18287.000000</td>\n",
       "      <td>279489.020000</td>\n",
       "      <td>248.000000</td>\n",
       "      <td>373.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         CustomerID         amount    frequency      recency   cluster_id\n",
       "count   4372.000000    4372.000000  4372.000000  4372.000000  4372.000000\n",
       "mean   15299.677722    1898.459701     5.075480    91.047118     0.751372\n",
       "std     1722.390705    8219.345141     9.338754   100.765435     0.444273\n",
       "min    12346.000000   -4287.630000     1.000000     0.000000     0.000000\n",
       "25%    13812.750000     293.362500     1.000000    16.000000     0.000000\n",
       "50%    15300.500000     648.075000     3.000000    49.000000     1.000000\n",
       "75%    16778.250000    1611.725000     5.000000   142.000000     1.000000\n",
       "max    18287.000000  279489.020000   248.000000   373.000000     2.000000"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grouped_df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'whiskers': [<matplotlib.lines.Line2D at 0x201cf36a910>,\n",
       "  <matplotlib.lines.Line2D at 0x201cf36abe0>],\n",
       " 'caps': [<matplotlib.lines.Line2D at 0x201cf36aeb0>,\n",
       "  <matplotlib.lines.Line2D at 0x201cf3761c0>],\n",
       " 'boxes': [<matplotlib.lines.Line2D at 0x201cf36a610>],\n",
       " 'medians': [<matplotlib.lines.Line2D at 0x201cf376490>],\n",
       " 'fliers': [<matplotlib.lines.Line2D at 0x201cf376760>],\n",
       " 'means': []}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAPL0lEQVR4nO3dX6icd53H8ffHtJtKo2tKT0tM4qZIXDY1GGHISr3xH23Wm9SLLvFCclGIFy3o4k3rTetFQRb/XG2FiMVcuOkGVBqka7cGRQRpPJGYNm2KwdbmmNActxVrwSyN373IU53kzDlnzpkzmeTX9wuGeeb7/H4z34Hkk4dfnmeeVBWSpLa8bd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XIcJekBhnuktQgw12SGmS4S1KDDHdJapDhLkkNMtwlqUGGuyQ1yHCXpAYZ7pLUIMNdkho06s06pInrfpn0qrZ27dpJt6DGGO66ql2OG3UkaeKGIHprcVlGkhpkuEtSgwx3SWqQ4S5JDRpbuCfZkeT5JCeT3Deuz5EkzTWWcE+yCvgP4F+ALcCnk2wZx2dJkuYa15H7duBkVf2mqv4PeBTYOabPkiRdYlznua8HTvW9ngH+uX9Akj3AHoD3vOc9Y2pDuthyL3ha6jzPi9ekjevIfdDfhIv+tFfV3qrqVVVvampqTG1IF6uqy/KQJm1c4T4DbOx7vQE4PabPkiRdYlzh/gtgc5JbkvwdsAs4OKbPkiRdYixr7lX1RpJ7gSeAVcAjVXV8HJ8lSZprbD8cVlWPA4+P6/0lSfPzClVJapDhLkkNMtwlqUGGuyQ1KFfCBRdJZoHfTroPaR43Ar+fdBPSAP9QVQOvAr0iwl26kiWZrqrepPuQlsJlGUlqkOEuSQ0y3KXF7Z10A9JSueYuSQ3yyF2SGmS4S1KDDHdpHkkeSXI2yTOT7kVaKsNdmt+3gR2TbkJaDsNdmkdV/RR4ZdJ9SMthuEtSgwx3SWqQ4S5JDTLcJalBhrs0jyT7gZ8D/5hkJsndk+5JGpY/PyBJDfLIXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQYa7JDXIcJekBv0/IZFlFapdtNYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.boxplot(grouped_df['recency'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'whiskers': [<matplotlib.lines.Line2D at 0x201cc024400>,\n",
       "  <matplotlib.lines.Line2D at 0x201cc0246d0>],\n",
       " 'caps': [<matplotlib.lines.Line2D at 0x201cc0249a0>,\n",
       "  <matplotlib.lines.Line2D at 0x201cc024c70>],\n",
       " 'boxes': [<matplotlib.lines.Line2D at 0x201cc024130>],\n",
       " 'medians': [<matplotlib.lines.Line2D at 0x201cc024f40>],\n",
       " 'fliers': [<matplotlib.lines.Line2D at 0x201cc004250>],\n",
       " 'means': []}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAASI0lEQVR4nO3dX2hc95nG8ef1WNa0ThwUogRbduNQvGacgU2pyC5UF9WW3YTeOL0oWJQSyFCvIR2321yo8Vy0eyHTiHWKEduq7ko0F9kJhv7zRbbdrBkoA0tTuYRE9qypqetGtbHVqKjBQWE0evfCx8rIPpJGf8ZH89P3A+LMvHOO5jXYjw/vnDk/c3cBAMKyJekGAADrj3AHgAAR7gAQIMIdAAJEuANAgLYm3YAkPfTQQ753796k2wCAlnLu3Lk/u3tn3GsbItz37t2rsbGxpNsAgJZiZlcWe42xDAAEiHAHgAAR7gAQoGXD3cz2mFnJzCpmdt7MvhbVv21mfzKzt6Kfz9cd86KZXTKzi2b2VDP/AACAuzXygeqspBfc/bdmdr+kc2b2RvTad9393+p3NrMDkg5JelzSLkn/Y2Z/4+619WwcALC4Zc/c3f2au/82evy+pIqkriUOOSjpNXf/0N0vS7ok6cn1aBa4l4rForLZrFKplLLZrIrFYtItAQ1b0czdzPZK+pSkX0elr5rZ22Y2amYdUa1L0rt1h01o6f8MgA2nWCyqUChoaGhIMzMzGhoaUqFQIODRMhoOdzO7T9KPJX3d3f8q6fuSPinpCUnXJJ24vWvM4XfdV9jMDpvZmJmNTU5OrrRvoKkGBgY0MjKi3t5etbW1qbe3VyMjIxoYGEi6NaAhDYW7mb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DQIAIdwAIEOEOAAEi3IFFmFlR0v9K2m9mE2aWS7onoFHcfgAAAsSZOwAEiHAHgAAR7gAQIMIdAAJEuANAgAh3AAgQ4Q4AAfp/lWrXO2Hg7RMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.boxplot(grouped_df['frequency'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'whiskers': [<matplotlib.lines.Line2D at 0x201cd62e1f0>,\n",
       "  <matplotlib.lines.Line2D at 0x201cd62e4c0>],\n",
       " 'caps': [<matplotlib.lines.Line2D at 0x201cd62e790>,\n",
       "  <matplotlib.lines.Line2D at 0x201cd62ea60>],\n",
       " 'boxes': [<matplotlib.lines.Line2D at 0x201cd60dee0>],\n",
       " 'medians': [<matplotlib.lines.Line2D at 0x201cd62ed30>],\n",
       " 'fliers': [<matplotlib.lines.Line2D at 0x201cd633040>],\n",
       " 'means': []}"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAD4CAYAAADy46FuAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAVlUlEQVR4nO3db4hddZ7n8fc3lYqRzGhHTTcxMUZaZylzYR0s0mr7oAtZteeJDthsamEM9KUzpNPFDMyTduqBbjeBEXZGMLst65DgH2avijPTCnbWrTUXmqIdtRxkTKx1DaO21YqJW+kokZhK+d0H91S8la6c3FRy783NvF9wuTffe34n3wviJ+f8fuecyEwkSTqVJd1uQJJ0fjMoJEmlDApJUimDQpJUyqCQJJVa2u0GzrUrrrgi169f3+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TE8DdWr+wNNT6rZemMyeAq5q+vNa4MMu9SKdkJktvTZs2MCePXvm1fbs2cOGDRtaGi91W5zv/yFGxFLg/wK3Ab8BXgP+U2buW2j7wcHBnJiY6GCHUrm+vj6OHj1Kf3//idrMzAzLly9ndna2i51JX4mI1zNzcKHvzvsjisw8DvwIeBGYBJ45VUhI56OBgQHGx8fn1cbHxxkYGOhSR9KZOe+DAiAzf5GZf5CZ38zM7d3uRzoTo6OjVKtV6vU6MzMz1Ot1qtUqo6Oj3W5NakkvTGZLPW14eBiAkZERJicnGRgYYPv27Sfq0vnuvJ+jOFPOUUjSmevpOQpJUncZFJKkUgaFJKmUQSFJKmVQSJJKXXCrniLiIPB+t/uQTuEK4JNuNyEt4OrMXLXQFxdcUEjns4iYONUSROl85aknSVIpg0KSVMqgkDrr0W43IJ0p5ygkSaU8opAklTIoJEmlDAqpAyJiV0QciIi93e5FOlMGhdQZjwF3drsJaTEMCqkDMvOXwHS3+5AWw6CQJJUyKCRJpQwKSVIpg0KSVMqgkDogImrAy8C/i4ipiKh2uyepVd7CQ5JUyiMKSVIpg0KSVMqgkCSVMigkSaUMCklSKYNCklTKoJAklfr/wvlIThSx1uMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.boxplot(grouped_df['amount'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "# two types of outliers:\n",
    "# - statistical\n",
    "# - domain specific"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# removing (statistical) outliers\n",
    "Q1 = grouped_df.amount.quantile(0.10)\n",
    "Q3 = grouped_df.amount.quantile(0.90)\n",
    "IQR = Q3 - Q1\n",
    "grouped_df = grouped_df[(grouped_df.amount >= Q1 - 1.5*IQR) & (grouped_df.amount <= Q3 + 1.5*IQR)]\n",
    "\n",
    "# outlier treatment for recency\n",
    "Q1 = grouped_df.recency.quantile(0.10)\n",
    "Q3 = grouped_df.recency.quantile(0.90)\n",
    "IQR = Q3 - Q1\n",
    "grouped_df = grouped_df[(grouped_df.recency >= Q1 - 1.5*IQR) & (grouped_df.recency <= Q3 + 1.5*IQR)]\n",
    "\n",
    "# outlier treatment for frequency\n",
    "Q1 = grouped_df.frequency.quantile(0.10)\n",
    "Q3 = grouped_df.frequency.quantile(0.90)\n",
    "IQR = Q3 - Q1\n",
    "grouped_df = grouped_df[(grouped_df.frequency >= Q1 - 1.5*IQR) & (grouped_df.frequency <= Q3 + 1.5*IQR)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4209, 3)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2. rescaling\n",
    "rfm_df = grouped_df[['amount', 'frequency', 'recency']]\n",
    "\n",
    "# instantiate\n",
    "scaler = StandardScaler()\n",
    "\n",
    "# fit_transform\n",
    "rfm_df_scaled = scaler.fit_transform(rfm_df)\n",
    "rfm_df_scaled.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>frequency</th>\n",
       "      <th>recency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.844245</td>\n",
       "      <td>-0.498797</td>\n",
       "      <td>2.280654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.423353</td>\n",
       "      <td>0.801164</td>\n",
       "      <td>-0.919107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.518321</td>\n",
       "      <td>0.021187</td>\n",
       "      <td>-0.198173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.488230</td>\n",
       "      <td>-0.758789</td>\n",
       "      <td>-0.751218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.590722</td>\n",
       "      <td>-0.758789</td>\n",
       "      <td>2.122641</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     amount  frequency   recency\n",
       "0 -0.844245  -0.498797  2.280654\n",
       "1  2.423353   0.801164 -0.919107\n",
       "2  0.518321   0.021187 -0.198173\n",
       "3  0.488230  -0.758789 -0.751218\n",
       "4 -0.590722  -0.758789  2.122641"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rfm_df_scaled = pd.DataFrame(rfm_df_scaled)\n",
    "rfm_df_scaled.columns = ['amount', 'frequency', 'recency']\n",
    "rfm_df_scaled.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 6. Modelling"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Finding the Optimal Number of Clusters\n",
    "\n",
    "### SSD"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x201d02909a0>]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "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7O6rwq5lgEx39yuBzwD3B12jQ1EKcCXwiLtfARwBBuzcZDyGfiNQFvW6FNgVUi0SJej//i3wC3d/Lux6BkLws/t1YFa4lfTLdODmoC/8WeA6M/t5uCX1n7vvCh6bgd8R6eodihqBxqhfj78hshMYEPEY+m8BlWY2LjgBMhtYGHJNCS84+fk4sMHd/yPses6FmRWZWV7wPBO4AdgYalH94O4Punupu5cT+X+yyN2/EXJZ/WJmWcEAAYKukE8BQ3LEm7vvARrM7OKg6XpgwAY8pAzUB8UKd+82s+8ALwPJwBPuvi7ksvrNzJ4BPgkUmlkj8C/u/ni4VfXLdOCbwNqgLxzgn939hfBK6rdRwPxgpFgSsMDdh/RwxzgwEvhd5NiCFOCX7v5SuCWdk+8CvwgOXLcBdw3UB8fdkE0REflo8di9IyIiH0GhLyKSQBT6IiIJRKEvIpJAFPoiIglEoS8ikkAU+iIiCeT/A/mmL0rmUn+8AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# elbow-curve/SSD\n",
    "ssd = []\n",
    "range_n_clusters = [2, 3, 4, 5, 6, 7, 8]\n",
    "for num_clusters in range_n_clusters:\n",
    "    kmeans = KMeans(n_clusters=num_clusters, max_iter=50)\n",
    "    kmeans.fit(rfm_df_scaled)\n",
    "    \n",
    "    ssd.append(kmeans.inertia_)\n",
    "    \n",
    "# plot the SSDs for each n_clusters\n",
    "# ssd\n",
    "plt.plot(ssd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For n_clusters=2, the silhouette score is 0.4979580758288508\n",
      "For n_clusters=3, the silhouette score is 0.49030867779024295\n",
      "For n_clusters=4, the silhouette score is 0.46060609327485974\n",
      "For n_clusters=5, the silhouette score is 0.4049759159738527\n",
      "For n_clusters=6, the silhouette score is 0.38430386862392385\n",
      "For n_clusters=7, the silhouette score is 0.3982293618580871\n",
      "For n_clusters=8, the silhouette score is 0.3894889882553682\n"
     ]
    }
   ],
   "source": [
    "# silhouette analysis\n",
    "range_n_clusters = [2, 3, 4, 5, 6, 7, 8]\n",
    "\n",
    "for num_clusters in range_n_clusters:\n",
    "    \n",
    "    # intialise kmeans\n",
    "    kmeans = KMeans(n_clusters=num_clusters, max_iter=50)\n",
    "    kmeans.fit(rfm_df_scaled)\n",
    "    \n",
    "    cluster_labels = kmeans.labels_\n",
    "    \n",
    "    # silhouette score\n",
    "    silhouette_avg = silhouette_score(rfm_df_scaled, cluster_labels)\n",
    "    print(\"For n_clusters={0}, the silhouette score is {1}\".format(num_clusters, silhouette_avg))\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-3 {color: black;background-color: white;}#sk-container-id-3 pre{padding: 0;}#sk-container-id-3 div.sk-toggleable {background-color: white;}#sk-container-id-3 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-3 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-3 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-3 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-3 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-3 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-3 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-3 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-3 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-3 div.sk-item {position: relative;z-index: 1;}#sk-container-id-3 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-3 div.sk-item::before, #sk-container-id-3 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-3 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-3 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-3 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-3 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-3 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-3 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-3 div.sk-label-container {text-align: center;}#sk-container-id-3 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-3 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-3\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KMeans(max_iter=50, n_clusters=3)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" checked><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KMeans</label><div class=\"sk-toggleable__content\"><pre>KMeans(max_iter=50, n_clusters=3)</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "KMeans(max_iter=50, n_clusters=3)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# final model with k=3\n",
    "kmeans = KMeans(n_clusters=3, max_iter=50)\n",
    "kmeans.fit(rfm_df_scaled)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 0, ..., 0, 2, 0])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kmeans.labels_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>amount</th>\n",
       "      <th>frequency</th>\n",
       "      <th>recency</th>\n",
       "      <th>cluster_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12346.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2</td>\n",
       "      <td>325</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12347.0</td>\n",
       "      <td>4310.00</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12348.0</td>\n",
       "      <td>1797.24</td>\n",
       "      <td>4</td>\n",
       "      <td>74</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12349.0</td>\n",
       "      <td>1757.55</td>\n",
       "      <td>1</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12350.0</td>\n",
       "      <td>334.40</td>\n",
       "      <td>1</td>\n",
       "      <td>309</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CustomerID   amount  frequency  recency  cluster_id\n",
       "0     12346.0     0.00          2      325           1\n",
       "1     12347.0  4310.00          7        1           2\n",
       "2     12348.0  1797.24          4       74           0\n",
       "3     12349.0  1757.55          1       18           0\n",
       "4     12350.0   334.40          1      309           1"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# assign the label\n",
    "grouped_df['cluster_id'] = kmeans.labels_\n",
    "grouped_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2499\n",
       "1    1058\n",
       "2     652\n",
       "Name: cluster_id, dtype: int64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grouped_df.cluster_id.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='cluster_id', ylabel='amount'>"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAAEHCAYAAACJN7BNAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAdCUlEQVR4nO3df3Bd5X3n8fdHsvlhHEKwDHYkZ+XWIikw3qZoGboZIBtjY6UB006y691JuNPAmrLUpss2CYRsmjBhNk1L0ogujL3Q5tJlQzw0XTsZCyyT8mN3HUBAYmMTx0pwQMEYyYbE4MRI1nf/uEfOlS3LV/K5OvfH5zVz557nOedcfa+F+NznOeeeo4jAzMzsRDVkXYCZmdUGB4qZmaXCgWJmZqlwoJiZWSocKGZmloppWReQlaampmhtbc26DDOzqvLMM88MRMTssdbVbaC0trbS09OTdRlmZlVF0s+Otc5TXmZmlgoHipmZpcKBYmZmqXCgmJlZKhwoZmYpGRgYYOXKlezduzfrUjLhQDEzS0k+n2fLli3k8/msS8mEA8XMLAUDAwN0dXUREXR1ddXlKMWBYma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mBUlv6gHlF7RbglYxqMas7kqZTCJP7I+LbWdcz1RwoteVpoE3SfEknAcuB9RnXZFYXJAm4F3ghIr6adT1ZcKDUkIgYAv4UeJjCAcG1EbEt26qsVJK+CWwG3iupT9I1WddkE/IB4BPAhyT9IHl8OOuippJPGzYzs1R4hGJmZqlwoJiZWSocKGZmlgoHipmZpcKBYmZmqXCgmJlZKhwoZimR9AVJfz6J/c6Q9J9SrGODpDPG6J9UfWalcqCYZe8MYEKBooIx/34j4sMR8UYKdZlNiAPFbJIkXS1pi6QfSvqHI9Y9Kqk9WW6StCtZPk/SU8m3qLdIagO+DPx20vdXyXafkvR0ss0Xk77W5OZNdwHPMvq6bcU/e5ekpmT51uSGa5uA95bnX8KsYFrWBZhVI0nnAbcCH4iIAUlnAqtK2PVPgK9HxP3J9dYagZuB8yPid5PXXgK0Ubi/jYD1yc23XqIQCn8cEccd0Ui6gML13N5P4W/9WQo3fTIrCweK2eR8CHgwIgYAImJf4dqAx7UZuFVSC/DtiNg5xn5LksdzSXsmhYB5CfhZRHy/xBovBv4pIg4ASPKFQq2sPOVlNjli/HvNDPGbv69TRjoj4n8BVwK/Ah6W9KFjvPZ/i4jfTR4LIuLeZN1bE6zTF+uzKeNAMZucR4B/K2kWQDLlVWwXcEGy/NGRTkm/Bfw0Ijop3FpgIbAfeEfRvg8Dn0xu1ISkZklnTaLGx4E/lHRqco/zKybxGmYl85SX2SRExDZJtwOPSTpEYXpqV9Emfw2slfQJ4HtF/f8O+LikQeBV4LZkuuz/Snoe6IqIT0n6HWBzMh32JvBx4NAEa3xW0reAHwA/A56YxFs1K5kvX29mZqnwlJeZmaXCU15mVUrSk8DJR3R/IiK2ZlGPmae8zMwsFZ7yMjOzVDhQzMwsFQ4UMzNLhQPFzMxS8f8B5CcF/9CRgHUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot\n",
    "sns.boxplot(x='cluster_id', y='amount', data=grouped_df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"font-family:verdana;\">\n",
    "    <h3 style=\"font-family:verdana;\">⭐Important Observations :</h3>\n",
    "    <div class=\"alert alert-block alert-info\">\n",
    "    * <i> Cluster <code>2</code> represents high monetary customers.</i><br>\n",
    "    * <i> Cluster <code>1</code> represents least monetary customers.</i><br>\n",
    "    </div>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='cluster_id', ylabel='frequency'>"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEHCAYAAACp9y31AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAUCklEQVR4nO3df5BddX3G8edZCL+y2AAJmLLUVTdYwUGULdORSqM2aBhF42ARC82oLbVVIyM6pSWBAOngWKO4ndpOHNCtAuIgqRmbCClCQYYSNuE3sWRLA16NZEOMkBAxyX76xz0Xd5dNcu7NPffs3e/7NXNn7zl777lPdmeffPe7536PI0IAgHR0lB0AANBaFD8AJIbiB4DEUPwAkBiKHwASc3DZAfKYPn16dHd3lx0DANrK2rVrt0TEjLH726L4u7u7NTAwUHYMAGgrtp8ebz9TPQCQGIofABJD8QNAYih+AEgMxQ8AiaH4ASAxFD8AJKYtzuMHkK6+vj4NDg42/biVSkWS1NXV1fRj9/T0aMGCBU0/brNQ/ACStHPnzrIjlIbiBzChFTVyrh23r6+vkONPZMzxA0BiKH4ASAzFDwCJofgBIDEUPwAkhuIHgMRQ/ACQGIofABJD8QNAYih+AEgMxQ8AiaH4ASA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o4Ip4vO0+rUPzlqXvNIgDNY3uKqqV/Q0TcWnaeVqL4y8OaRUBJbFvSdZLWR8SXy87TahR/SSJit6TamkXrJX2XNYvah+2bJN0n6Q22K7Y/XnYm1OUMSRdKeqfth7Lb2WWHahVO5wSAxDDiB4DEUPwAkBiKHwASQ/EDQGIofgBIDMUPAImh+JEk24ttf66B502z/TdNzLHS9rRx9jeUD8iD4gfqM01SXcXvqnF/1iLi7IjY1oRcQG4UP5Jg+89tP2L7YdvfGvO5u2z3Zven296Y3T/Z9prsXZ2P2J4l6QuSXp/t+8fscZ+3/UD2mCuzfd3ZRT6+JmmdRq/LNPK1N9qent2/LLswz39KekMxXwlAOrjsAEDRbJ8s6TJJZ0TEFttHS1qQ46mfkPTViLghW0/pIEmXSnpTRJyaHfssSbNUvb6CJa3ILtLyjKrl/dGI2O9vCLZPU3W9preo+nO5TtWLgwBNR/EjBe+UdEtEbJGkiNhaXaNrv+6TdJntLkm3RsSGcZ53VnZ7MNvuVPU/gmckPR0R/50z49slLY+IFyXJNgv2oTBM9SAF1r6vdbBbv/1ZOKy2MyJulHSOpJ2SbrP9zr0c+5qIODW79UTEddnndtSZk4Wz0BIUP1Jwh6Q/tX2MJGVTPSNtlHRadv/c2k7br5P0VET0qbpk9imSXpB05Ijn3ibpY9kFPWT7eNvHNpDxbknzbB+eXQP2fQ0cA8iFqR5MehHxuO1/kPRftveoOi2zccRDviTpu7YvlPSjEfvPk3SB7V2SfiHpqmya6F7bj0laFRGft/1GSfdl00DbJV0gaU+dGdfZvlnSQ5KelnRPA/9UIBeWZQaAxDDVAwCJYaoHaAHb90s6dMzuCyPi0TLyIG1M9QBAYpjqAYDEUPwAkBiKHwASQ/EDQGL+H8hdc5Vpq2ORAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.boxplot(x='cluster_id', y='frequency', data=grouped_df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"font-family:verdana;\">\n",
    "    <h3 style=\"font-family:verdana;\">⭐Important Observations :</h3>\n",
    "    <div class=\"alert alert-block alert-info\">\n",
    "    * <i> Cluster <code>2</code> represents high frequency customers.</i><br>\n",
    "    * <i> Cluster <code>1</code> represents least frequency customers.</i><br>\n",
    "    </div>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='cluster_id', ylabel='recency'>"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEHCAYAAABBW1qbAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAaFElEQVR4nO3df3Bd5X3n8fdH/gEmTscYGddY9opGdiaQATPVeLtlwq9gjJkFQ6e0zmyopiXrdBZwMmmygYaJY4JnmaUhi5iQrClM1W4a6mmSiU3NGkMDThoCiB9xsAnoLgj7Rq6xDAQMwbbs7/5xjw5XQpavbJ17JJ/Pa+bOvc9zzzn3Kwvxueec55xHEYGZmRlAQ94FmJnZ2OFQMDOzlEPBzMxSDgUzM0s5FMzMLDUx7wKORWNjYzQ3N+ddhpnZuPL000/3RsSMod4b16HQ3NxMZ2dn3mWYmY0rkl493Hs+fGRmZimHgpmZpRwKZmaWciiYmVnKoWBmZimHgpmZpRwKZmaWGtfXKZgdi/b2dkqlUibbLpfLADQ1NY36tltaWlixYsWob9cMHApmmfjtb3+bdwlmR8WhYIWV5bft/m23t7dn9hlmWfA5BTMzSzkUzMws5VAwM7OUQ8HMzFIOBTMzSzkUzMws5VAwM7NUZqEg6URJT0r6haStklYl/V+T9Gt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i4I+968uBQGIMiog+4HthI5UTX2ojYmm9VVitJ3wMeBz4qqSzp2rxrspqdC1wDXCTpueRxWd5F1ZOHpJqZWcp7CmZmlnIomJlZyqFgZmYph4KZmaUcCmZmlnIomJlZyqFgVkXS1yR98SjWmybpv41iHRskTRui/6jqM6uVQ8FsdEwDRhQKqhjybzAiLouIN0ehLrMRcShYoUn6M0lbJP1C0j8Meu9RSa3J60ZJ3cnrMyU9mVztukXSPOA24CNJ3+3Jcl+S9FSyzKqkrzmZwOVu4BkG3uOq+rO7JTUmr7+STLj0MPDRbP4lzCom5l2AWV4knQl8BTg3InolTQdW1LDqXwJ3RsR3k3tTTQBuBD4eEQuSbV8CzKMyN4aAdcnkO9up/I/9zyPiiHsWkn6fyr2vzqHy9/oMlYlfzDLhULAiuwj454joBYiI1yv3Qzuix4GvSGoCfhARXUOsd0nyeDZpT6USEtuBVyPi5zXW+AnghxHxLoAk3xjRMuXDR1ZkYvh5Kvp4/2/kxP7OiPhH4Argt8BGSRcdZtv/IyIWJI+WiLg3ee+dEdbpG5RZ3TgUrMgeAf5E0ikAyeGjat3A7yev/7i/U9LvAS9HRDuVW5qfBbwNfLhq3Y3AXySTtSBptqRTj6LGzcBVkqYkcwZffhTbMKuZDx9ZYUXEVkmrgcckHaRyqKe7apG/AdZKugb416r+PwU+LekA8O/ALcmhp3+T9DzwYER8SdLHgMeTQ0t7gU8DB0dY4zOS/gl4DngV+MlR/KhmNfOts83MLOXDR2ZmlvLhI7McSXoCOGFQ9zUR8cs86jHz4SMzM0v58JGZmaUcCmZmlnIomJlZyqFgZmap/w9f4iETKvPujQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.boxplot(x='cluster_id', y='recency', data=grouped_df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"font-family:verdana;\">\n",
    "    <h3 style=\"font-family:verdana;\">⭐Important Observations :</h3>\n",
    "    <div class=\"alert alert-block alert-info\">\n",
    "    * <i> Cluster <code>2</code> represents high recency customers.</i><br>\n",
    "    * <i> Cluster <code>1</code> represents least recency customers.</i><br>\n",
    "    </div>\n",
    "</div>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
